<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-09-22 16:05
 *
 * 项目：rm  -  $  - load_mini_js.php
 *
 * 作者：liwei 
 */

//
//web-view 文档: https://smartprogram.baidu.com/docs/develop/component/open_web-view/
?>


<script>
    jQuery(function () {
        if (navigator.userAgent.indexOf('<?=$type?>') > -1 && navigator.userAgent.indexOf('swan') > -1) {
            jQuery('script#bdumini-appx-web-view-js').length <1 &&
            jQuery('body').append(
                '<' + 'script id="bdumini-appx-web-view-js" type="text/javascript" ' +
                'src="https://b.bdstatic.com/searchbox/icms/searchbox/js/swan-2.0.23.js"' + '>' + '<' + '/' + 'script' + '>'
            );

            aliminiInit(0);
            function aliminiInit(loadNum) {
                window.setTimeout(function () {
                    if (typeof swan === "undefined") {
                        loadNum += 1;
                        loadNum <5 ? aliminiInit(loadNum) : levtoast('百度小程序JS加载失败');
                        return;
                    }
                    // swan.webView.postMessage({
                    //     pageInfo: {
                    //         title: jQuery('title').text(),
                    //         keywords: jQuery('head meta[name="keywords"]').attr('content'),
                    //         description: jQuery('head meta[name="description"]').attr('content'),
                    //     }
                    // });
                    var nowTime = new Date().getTime();
                    if (actionLocalStorage('baiduAD') < nowTime - 3600*levrandom(1, 4)*1000) {
                        Levme.showNotices('即将进入广告，看广告30秒有奖！到时自动关闭！' +
                            '<a class="vera button-small button button-fill scale7 adHideBtn wdmin wd30 inblk color-gray">取消</a>' +
                            '<a class="vera button-small button button-fill scale7 adShowBtn wdmin wd30 inblk"><sec></sec>确定</a>' +
                            '', 'info', 35*1000);
                        timer(5);
                    }
                }, 100);
            }
            function timer(sec) {
                if (sec < 1) {
                    showAD();
                    return;
                }
                sec -= 1;
                window.setTimeout(function () {
                    timer(sec);
                    jQuery('.adShowBtn sec').html(sec);
                }, 1000);
            }
            function showAD() {
                if (!adShowBtn) return;
                var nowTime = new Date().getTime();
                adShowBtn = 0;
                actionLocalStorage('baiduAD', nowTime);
                swan.webView.navigateTo({url: '/pages/ads/ads'});
                window.setTimeout(function () {
                    swan.webView.navigateBack({delta:1});
                }, 30*1000);
            }
            var adShowBtn = 1;
            Levme.onClick('.adShowBtn', function () {
                showAD();
            });
            Levme.onClick('.adHideBtn', function () {
                adShowBtn = 0;
            });
        }
    });
</script>
